﻿using MediatR;
using Traceability.App.Apilication.Common.Breeding;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler.Breeding
{
    public class GetBreedingEnterHandler : IRequestHandler<GetBreedingEnterCommon, ApiResult<List<BreedingEnterprises>>>
    {
        private readonly IBaseRespository<BreedingEnterprises> breedingEnterRepo;

        public GetBreedingEnterHandler(IBaseRespository<BreedingEnterprises> breedingEnterRepo)
        {
            this.breedingEnterRepo = breedingEnterRepo;
        }
        public Task<ApiResult<List<BreedingEnterprises>>> Handle(GetBreedingEnterCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<BreedingEnterprises>> res=new ApiResult<List<BreedingEnterprises>>();

            var info = breedingEnterRepo.GetAll().Where(x=>x.Production_Batch==request.Production_Batch).ToList();

            res.Message = "根据生产批次查询养殖企业";
            res.Code=ApiEnum.Success;
            res.Data = info;
            return Task.FromResult(res);


        }
    }
}
